<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        //基于promise发送ajax请求
        const loadData = function(url) {
            const p = new Promise(function(resolve, reject) {
                //使用原生的js实现ajax请求
                const xhr = new XMLHttpRequest();
                //定义请求方法和请求路径
                xhr.open('get', url);
                //监听状态
                xhr.onreadystatechange = function() {
                        if (xhr.readyState != 4) return;
                        //正确的情况
                        if (xhr.readyState == 4 && xhr.status == 200) {
                            //处理正确的结果
                            resolve(xhr.responseText);
                        } else {
                            reject('服务器错误');
                        }
                    }
                    //发送数据,通常get请求必须发送null
                xhr.send(null);
            });
            return p;
        }

        loadData('http://localhost:3000/jq01').then(function(data) {
            console.log(data);
            return loadData('http://localhost:3000/jq02');
        }).then(function(data) {
            console.log(data);
            return loadData('http://localhost:3000/jq03');
        }).then(function(data) {
            console.log(data);
        });
    </script>
</body>

</html>